#pragma once
#ifndef _D3D_LIGHT_
#define _D3D_LIGHT_

#include "..\common\def.h"
#include "interface_types.h"
#include "d3d_util.h"
struct RenderTarget; 
class CD3D9Device; 

struct EE_EXPORT D3DLight : public IResource
{	
	
protected:
	struct ShaderData
	{
		static const int size; 
		float position[4]; 
		float direction[4]; // = {0.0f,0.0f,0.0f,1.0f}; 
		float diffuseColor[4]; // = {1.0f,1.0f,1.0f,0.0f}; 
		float ambientColor[4]; // = {0.0f,0.0f,0.0f,0.0f}; 
		float aux[4]; // = 1.0f; 
		float lightViewProj[16]; 
	}; 

	Color3f		DiffuseColor; 
	Color3f		AmbientColor; 
	float		Attenuation; 
	ShaderData	m_ShaderData; 

	D3DLight(CD3D9Device* pDevice); 
public:
	D3DXVECTOR3	m_Position; 
	enum LightState { LIGHT_ON = 1, LIGHT_OFF = 0};
	friend class CD3D9Device; 
	HRESULT Release(); 
	HRESULT Reload(); 
	
string GetType() const; 

	void SetState(const LightState state);
	LightState GetState();
	virtual void SetPosition(const Vector3f& position); 
	void SetAttenuation(const float intensity); 
	void SetDiffuseColor(const Color3f &color); 
	void SetAmbientColor(const Color3f &color); 
	
	void SetLightCoefficents(const float ambient, const float diffuse, const float specular);
	virtual ShaderData* GetShaderData(); 
protected:
	LightState m_State;
}; 

struct EE_EXPORT D3DDirectionalLight : public D3DLight
{
	friend class CD3D9Device; 
	friend struct D3DLightShader; 
private:

	ViewOrrientation m_ViewOrrientation;
	RenderTarget* mDepthBuffer; 
	D3DXVECTOR3	m_Direction; 
	float m_Range;
	bool mb_Shadow; 
	bool m_UpdatePending;
public:
	D3DDirectionalLight(CD3D9Device* const pDevice); 
	virtual ~D3DDirectionalLight(); 
	HRESULT Reload(); 
	HRESULT SetShadow(const bool hasShadow); 
	void Update(); 
	HRESULT Release(); 
	D3DLight::ShaderData* D3DDirectionalLight::GetShaderData(); 
	bool IsShadowed(); 
	void SetDirection(const Vector3f& direction); 
	void SetPosition(const Vector3f& position); 
	void SetRange(const float range);
	string GetType() const; 
	ViewOrrientation* GetViewOrrientation();
}; 

#endif